<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>采购发布</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../css/css.css" />
</head>

<body>
<style>
    [v-cloak] {
        display: none;
    }
</style>
    <div v-cloak id="wrap" class="flex-wrap flex-vertical">
        <header>
            <ul>
                <li class="active">
                    <i onclick="back()" class="icon iconfont icon-back"></i>
                    <span>采购发布</span>
                </li>
            </ul>
        </header>
        <div class="procurementrelease fixed-header">
            <div>
                <div class="reg-form">
                    <div class="reg-form1">
                        <span><i>*</i>名称</span>
                        <div class="reg-input">
                            <input class="w100" v-model="titles" type="text" placeholder="请输入商品">
                        </div>
                    </div>
                    <div class="reg-form1">
                        <span><i>*</i>数量</span>
                        <div class="reg-input">
                            <input class="w100" v-model="amount" type="number" placeholder="请输入数量">
                        </div>
                    </div>
                    <div class="reg-form1">
                        <span><i>*</i>时间</span>
                        <div class="reg-input reg-inputdata" @click="selectData">
                            <input class="w100" readonly="readonly" type="text" v-model="supplytime" placeholder="请输入时间">
                            <i class="icon iconfont icon-rili"></i>
                        </div>
                    </div>
                    <div class="reg-form1">
                        <span><i>*</i>地点</span>
                        <div class="reg-input">
                            <input class="w100" v-model="address" type="text" placeholder="请输入地点">
                        </div>
                    </div>
                </div>
                <div class="login-form" @click="submitSupply">
                    <div class="sub-login">
                        提交
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script src="../../aui/js/aui.js"></script>
<script src="../../script/vue2.js"></script>
<script src="../../script/jquery.min.js"></script>
<script src="../../script/vue-resource.min.js"></script>
<script src="../../script/common.js"></script>
<script type="text/javascript">
var vm = new Vue({
    el: "#wrap",
    data: {
        category: 0,
        showSelectData: false,
        currentDate: new Date(),
        supplytime: '',
        price: '',
        titles: '',
        mobile: '',
        address: '',
        img: '',
        amount: ''
    },
    mounted: function() {
        var that = this;
        apiready = function() {
            that.category = api.pageParam.name
            // alert(that.type)
            api.addEventListener({
                name: 'viewdisappear'
            }, function() {
                api.closeWin();
            });
            if (!$api.getStorage('userInfo')) { //判断是否登录
                if (api.systemType == "ios") {
                    var times = 0;
                } else {
                    var times = 300;
                }
                api.openWin({ //未登录打开登陆窗口
                    name: 'login',
                    url: './html/login/login.html',
                    delay: times,
                    slidBackType: 'edge',
                    vScrollBarEnabled: false,
                    slidBackEnabled: false,
                })
            } else {}
        };
    },
    methods: {
        submitSupply: function() {
            var that = this;
            var token = $api.getStorage('userInfo').token
            if (that.titles == '') {
                api.toast({ msg: '请输入标题', location: 'middle' });
                return
            }
            if (that.amount == '') {
                api.toast({ msg: '请输入数量', location: 'middle' });
                return
            }
            if (that.supplytime == '') {
                api.toast({ msg: '请选择日期', location: 'middle' });
                return
            }
            if (that.address == '') {
                api.toast({ msg: '请输入地址', location: 'middle' });
                return
            }
            api.ajax({
                url: ajaxRoute.caisubmit,
                method: 'post',
                data: {
                    values: {
                        token: token,
                        title: that.titles,
                        category: that.category,
                        amount: that.amount,
                        supplytime: that.supplytime,
                        address: that.address,
                    }
                }
            }, function(res, err) {
                api.hideProgress();
                // alert(res)
                if (res.code == 1) {
                    api.toast({ msg: '提交成功', location: 'middle' });
                    api.confirm({
                        title: '信息已提交成功',
                        msg: '是否继续发布',
                        buttons: ['是', '否']
                    }, function(ret, err) {
                        var index = ret.buttonIndex;
                        if (index == 1) {
                            window.location.reload();
                        } else {
                            openWinto('supply', '../procurement/order', 1)
                        }
                    });

                } else {
                    api.hideProgress();
                    api.toast({ msg: res.msg, location: 'middle' });
                }
            })
        },
        upLoadimg: function() {
            var that = this;
            api.getPicture({
                sourceType: 'library',
                encodingType: 'jpg',
                mediaValue: 'pic',
                destinationType: 'base64',
                quality: 50,
                targetWidth: 750,
                targetHeight: 750
            }, function(ret, err) {
                if (ret) {
                    that.onRead(ret.base64Data)
                } else {
                    // alert(JSON.stringify(err));
                }
            });
        },
        onRead: function(file) {
            var that = this;
            showProgress();
            var token = $api.getStorage('userInfo').token
            api.ajax({
                url: ajaxRoute.uploadthumb,
                method: 'post',
                data: {
                    values: {
                        token: token,
                        imgData: file
                    }
                }
            }, function(res, err) {
                api.hideProgress();
                // alert(res)
                if (res.code == 1) {
                    api.toast({ msg: '上传成功', location: 'middle' });
                    that.img = res.data
                } else {
                    api.hideProgress();
                    api.toast({ msg: res.msg, location: 'middle' });
                }
            })
        },
        selectData: function() {
            var that = this;
            api.openPicker({
                type: 'date',
                // date: '2014-05-01 12:30',
                title: '选择日期'
            }, function(ret, err) {
                if (ret) {
                    // alert(JSON.stringify(ret));
                    that.supplytime = ret.year + '-' + ret.month + '-' + ret.day
                } else {
                    alert(JSON.stringify(err));
                }
            });
            // this.showSelectData = !this.showSelectData
        },
        cancelSelectData: function() {
            this.showSelectData = !this.showSelectData
        },
        confirmSelectData: function(e) {
            this.supplytime = utils.formatDate(e, 'yyyy-MM-dd');
            this.showSelectData = !this.showSelectData
        }
    },
    filters: {
        filtersImg(img) {
            var imgs = ajaxUrl + '/' + img
            return imgs;
        }
    },
})
</script>
